<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<div id="company" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    <?=$this->lang->line("Data Entry")?> > <?=$this->lang->line("Company")?>
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24"><?=$this->lang->line("TodayIS")?> <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="list-div">
        <?php echo form_open('index/company'); ?>
        <table class="top-table">
            <tr>
                <td><?=$this->lang->line("CompanyList")?><input type="hidden" value="<?=$ordername?>" name="ordername" id="ordername" /></td>
                <td width="240" class="center"><input type="text" placeholder="<?=$this->lang->line("searchmsg")?>" 
                    name="condition" value="<?=$condition?>"/></td>
                <td width="90" class="center"><input type="submit" value="<?=$this->lang->line("Search")?>" /></td>
                <td width="110" class="center"><input type="button" value="<?=$this->lang->line("New")?>" id="new"/></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table class="list-table">
            <tr>
                <th width="50" class="order" ordername="c.sn"><?=$this->lang->line("SN")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="120" class="order" ordername="c.name"><?=$this->lang->line("CompanyName")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="i.name"><?=$this->lang->line("Industry")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="130" class="order" ordername="c.person"><?=$this->lang->line("ContactPerson")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="c.position"><?=$this->lang->line("Position")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th width="100" class="order" ordername="c.number"><?=$this->lang->line("ContactNo")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <th class="order" ordername="c.email"><?=$this->lang->line("Email")?><img src="<?=base_url()?>resource/img/arrow_no.png" /></th>
                <?php if($this->session->userdata('department') == 1){?>
                <th width="60"></th>
                <th width="60"></th>
                <?php }?>
            </tr>
            <?php foreach ($companys as $key => $value) {?>
            <tr>
                <td><?=$value['sn']?></td>
                <td><?=$value['name']?></td>
                <td><?=$value['industryname']?></td>
                <td><?=$value['person']?></td>
                <td><?=$value['position']?></td>
                <td><?=$value['number']?></td>
                <td><?=$value['email']?></td>
                <?php if($this->session->userdata('department') == 1){?>
                <td><a href="javascript:void(0)" class="buttona detail" companyid="<?=$value['id']?>"><img src="<?=base_url()?>resource/img/detail.png"/><?=$this->lang->line("Edit")?></a></td>
                <td><a href="javascript:void(0)" class="buttona delete" companyid="<?=$value['id']?>">
                        <img src="<?=base_url()?>resource/img/delete.png"/><?=$this->lang->line("Delete")?></a></td>
                <?php }?>
            </tr>
            <?php }
            if(count($companys) == 0){?>
            <tr>
                <td colspan="9">
                    NO DATA
                </td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="9" class="pagination">
                    <?php echo $page;?>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
$(".detail").click(function(){
    var id = $(this).attr("companyid");
    var url = '<?=base_url()?>index/company_detail/'+id;
    location.href=url;
});

$(".delete").click(function(){
    if(confirm("Are you sure delete this company?")){
        var id = $(this).attr("companyid");
        var url = '<?=base_url()?>index/deletecompany?id='+id;
        location.href=url;
    }
});

$("#new").click(function(){
    var url = '<?=base_url()?>index/new_company';
    location.href=url;
});

var url = '<?=base_url()?>index/company';
var order = "<?=$ordername?>";
var orders = order.split(" ");
$("th").each(function(){
    var ordername = $(this).attr("ordername");
    if(orders[0] == ordername){
        $(this).children("img").attr("src","<?=base_url()?>resource/img/arrow_"+orders[1]+".png");
    }
});
</script>
